package com.tich.common.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tich.common.domain.dto.AreaSelectDTO;
import com.tich.common.domain.entity.Area;
import com.tich.common.domain.vo.AreaVO;
import com.tich.common.mapper.AreaMapper;
import com.tich.common.service.IAreaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tich.enumration.AreaType;
import com.tich.enumration.IsStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 地区表 服务实现类
 * </p>
 *
 * @author 
 * @since 2025-05-14
 */
@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements IAreaService {

    @Autowired
    private AreaMapper areaMapper;

    /**
     * 查询省级数据
     * @param typeId
     * @return
     * */
    public List<AreaVO> selectByTypeId(Integer typeId) {
        //TODO 查询redis
        List<Area> areas = lambdaQuery().eq(Area::getType, typeId).list();
        return BeanUtil.copyToList(areas, AreaVO.class);
    }

    /**
     * 查询数据根据id集合
     * @param areaSelectDTO
     * @return
     * */
    public List<AreaVO> selectByIdList(AreaSelectDTO areaSelectDTO) {
        //构造查询条件
        LambdaQueryWrapper<Area> areaLambdaQueryWrapper = Wrappers.lambdaQuery(Area.class)
                .in(Area::getId, areaSelectDTO.getIdList());
        List<Area> areas = areaMapper.selectList(areaLambdaQueryWrapper);
        return BeanUtil.copyToList(areas, AreaVO.class);
    }

    /**
     * 查询当前地区的子地区
     * @param id
     * @return
     * */
    public List<AreaVO> getSonArea(Long id) {
        List<Area> list = lambdaQuery().eq(Area::getParentId, id).list();
        return BeanUtil.copyToList(list, AreaVO.class);
    }


}
